// SCENARIO SCRIPT

// This is the special script for your entire scenario. It contains
// special encounters and code accessible from anywhere in the scenario. it also
// contains the code that initializes important special things in the
// scenario (like shops and names and descriptions of special items).

// You can create your own states, but you should give all of them numbers greater than
// or equal to 10.
//
// global flags:
// 50, 0  = Quest given flag
// 50, 1  = 'Won' flag
// 50, 2  = Know how to put staff together again
// 50, 3  = Staff put together
// 51, 0  = Staff piece found in graveyard
// 51, 1  = Can find crevasse by Corinth
// 51, 2  = Staff piece found by Corinth
// 51, 3  = Know about 'fake' wall in Thessalonica mine
// 51, 4  = Staff piece found in Thessalonica mine
// 51, 5  = Staff piece found in Philippi (sewers)
// 51, 6  = Staff piece found in Tangramayne mine
// 51, 7  = Staff piece found in Bob's cave (Ephesus)
// 51, 8  = Kicked toy/inspected picture, activated mouth in Bob's cave
// 51, 9  = Bought staff piece from Wanda (Colosse)
// 51, 10 = Charlie can show way to Tangramayne mine
// 52, 0  = Flag (went into mine tunnels from Tangramayne mine)
// 100, 0 = variable town flag (sage's hut)
// 100, 1 = variable town flag (dargoth)
// 100, 2 = variable town flag (cornith, thessalonica, philippi, tangramayne, ephesus, colosse)
// 101, 0 = starting party level

beginscenarioscript;

variables;

short choice, i, e, lvl;

body;

// This is the state that is called every time the scenario is loaded,
// even when a save file in the scenario is loaded. Some things that should go here:
//    Names and descriptions of special items.
//    Names and effects of custom special abilities.
beginstate LOAD_SCEN_STATE;
	// quests
	init_quest(0, "Restore Staff", "Find the pieces of the Staff of Turin, restore it and bring back peace and prosperity.");

	// special items
	init_special_item(1, "Staff Shaft 1", "The bottom piece of a staff shaft.");
	init_special_item(2, "Staff Shaft 2", "A middle piece of a staff shaft.");
	init_special_item(3, "Staff Shaft 3", "A middle piece of a staff shaft.");
	init_special_item(4, "Staff Shaft 4", "A middle piece of a staff shaft.");
	init_special_item(5, "Staff Shaft 5", "A middle piece of a staff shaft.");
	init_special_item(6, "Staff Shaft 6", "A middle piece of a staff shaft.");
	init_special_item(7, "Staff Head", "An ornate piece that attaches to a staff.");
	init_special_item(8, "Room Key", "A room key for the Rosewood Inn in Dargoth.");
	init_special_item(9, "Training Key", "Key used for entering the training center in Corinth.");
	init_special_item(10, "Small Gold Key", "A small gold key found on a Zanta follower corpse.");
	init_special_item(11, "Room Key", "A room key for Sailors Roost in Philippi.");
	init_special_item(12, "Staff Piece", "A piece of a staff, just not the staff of Turin.");
break;

// This is the state that is called only once at the very beginning of 
// the scenario. Some things that should go here:
//    The stuff in shops.
//    Creating horses and boats.
beginstate START_SCEN_STATE;
	// Initialize a few shops.

	// Shop 0 - souvenir (Dargoth)
	add_item_to_shop(0, 404, 25);
	add_item_to_shop(0, 408, 20);
	add_item_to_shop(0, 417, 50);
	add_item_to_shop(0, 451, 5);

	// Shop 1 - food (Rosewood Inn, Sailors Roost, Feed Bag)
	add_item_to_shop(1, 4, 500);
	add_item_to_shop(1, 6, 500);
	add_item_to_shop(1, 7, 500);
	add_item_to_shop(1, 8, 500);
	add_item_to_shop(1, 12, 500);

	// Shop 2 - mining supplies (Thessalonica)
	add_item_to_shop(2, 161, 5);
	add_item_to_shop(2, 170, 500);
	add_item_to_shop(2, 171, 500);
	add_item_to_shop(2, 172, 30);
	add_item_to_shop(2, 177, 500);
	add_item_to_shop(2, 318, 5);
	add_item_to_shop(2, 319, 5);

	// Shop 3 - weapons (Philippi)
	add_item_to_shop(3, 47, 10);
	add_item_to_shop(3, 52, 10);
	add_item_to_shop(3, 57, 8);
	add_item_to_shop(3, 62, 4);
	add_item_to_shop(3, 77, 4);
	add_item_to_shop(3, 87, 4);
	add_item_to_shop(3, 92, 2);
	add_item_to_shop(3, 97, 2);
	add_item_to_shop(3, 101, 500);
	add_item_to_shop(3, 106, 500);

	// Shop 4 - armor (Philippi)
	add_item_to_shop(4, 27, 5);
	add_item_to_shop(4, 32, 5);
	add_item_to_shop(4, 37, 3);
	add_item_to_shop(4, 42, 2);
	add_item_to_shop(4, 114, 8);
	add_item_to_shop(4, 123, 5);
	add_item_to_shop(4, 128, 3);
	add_item_to_shop(4, 133, 2);
	add_item_to_shop(4, 143, 3);
	add_item_to_shop(4, 148, 3);

	// Shop 5 - pawn, buy only (Philippi, Colosse)
	add_item_to_shop(5, 196, 500);
	add_item_to_shop(5, 197, 500);
	add_item_to_shop(5, 198, 500);

	// Shop 6 - general store (Philippi)
	add_item_to_shop(6, 18, 10);
	add_item_to_shop(6, 22, 10);
	add_item_to_shop(6, 23, 10);
	add_item_to_shop(6, 171, 500);
	add_item_to_shop(6, 172, 50);
	if (get_ran(1, 1, 100) > 50) { add_item_to_shop(6, 175, get_ran(1, 10, 30)); }
	if (get_ran(1, 1, 100) > 75) { add_item_to_shop(6, 176, get_ran(1, 5, 15)); }
	add_item_to_shop(6, 178, 20);
	add_item_to_shop(6, 415, 5);

	// shop 7 - potions (Colosse)
	add_item_to_shop(7, 220, 7);
	add_item_to_shop(7, 223, 7);
	add_item_to_shop(7, 225, 7);
	add_item_to_shop(7, 228, 5);
	add_item_to_shop(7, 229, 5);
	add_item_to_shop(7, 231, 5);
	if (get_ran(1, 1, 100) > 75) { add_item_to_shop(7, 236, get_ran(1, 2, 4)); }
	if (get_ran(1, 1, 100) > 75) { add_item_to_shop(7, 237, get_ran(1, 2, 4)); }
	if (get_ran(1, 1, 100) > 75) { add_item_to_shop(7, 238, get_ran(1, 2, 4)); }

	// shop 8 - scrolls (Colosse)
	add_item_to_shop(8, 244, 5);
	add_item_to_shop(8, 248, 5);
	add_item_to_shop(8, 251, 4);
	add_item_to_shop(8, 253, 4);
	add_item_to_shop(8, 254, 4);
	add_item_to_shop(8, 257, 4);
	add_item_to_shop(8, 258, 4);
	add_item_to_shop(8, 260, 2);
	add_item_to_shop(8, 261, 2);

	// shop 9 - wands (Colosse)
	add_item_to_shop(9, 282, 4);
	add_item_to_shop(9, 283, 4);
	add_item_to_shop(9, 284, 4);
	add_item_to_shop(9, 285, 4);
	add_item_to_shop(9, 286, 4);
	add_item_to_shop(9, 287, 4);
	add_item_to_shop(9, 288, get_ran(1, 2, 4));
	add_item_to_shop(9, 289, get_ran(1, 2, 4));

	// shop 10 - priest spells (Colosse)
	add_item_to_shop(10, 3000, 5);
	add_item_to_shop(10, 3001, 5);
	add_item_to_shop(10, 3002, 5);
	add_item_to_shop(10, 3003, 5);
	add_item_to_shop(10, 3004, 5);
	add_item_to_shop(10, 3005, 4);
	add_item_to_shop(10, 3006, 4);
	add_item_to_shop(10, 3007, 4);
	add_item_to_shop(10, 3008, 4);
	add_item_to_shop(10, 3010, 3);
	add_item_to_shop(10, 3011, 3);
	add_item_to_shop(10, 3012, 3);
	add_item_to_shop(10, 3013, 3);
	add_item_to_shop(10, 3014, 3);
	add_item_to_shop(10, 3018, 2);

	// shop 11 - mage spells (Colosse)
	add_item_to_shop(11, 2000, 5);
	add_item_to_shop(11, 2001, 5);
	add_item_to_shop(11, 2002, 5);
	add_item_to_shop(11, 2003, 5);
	add_item_to_shop(11, 2004, 4);
	add_item_to_shop(11, 2005, 4);
	add_item_to_shop(11, 2006, 4);
	add_item_to_shop(11, 2007, 4);
	add_item_to_shop(11, 2008, 4);
	add_item_to_shop(11, 2010, 3);
	add_item_to_shop(11, 2011, 3);
	add_item_to_shop(11, 2014, 3);
	add_item_to_shop(11, 2016, 3);
	add_item_to_shop(11, 2018, 2);

	// shop 12 - magic armor (Colosse Hue)
	if (get_ran(1, 1, 100) > 50) { add_item_to_shop(12, 354, 1); }
	if (get_ran(1, 1, 100) > 50) { add_item_to_shop(12, 355, 1); }
	if (get_ran(1, 1, 100) > 50) { add_item_to_shop(12, 356, 1); }
	if (get_ran(1, 1, 100) > 50) { add_item_to_shop(12, 360, 1); }
	if (get_ran(1, 1, 100) > 50) { add_item_to_shop(12, 364, 1); }
	if (get_ran(1, 1, 100) > 50) { add_item_to_shop(12, 367, 1); }
	if (get_ran(1, 1, 100) > 50) { add_item_to_shop(12, 368, 1); }
	if (get_ran(1, 1, 100) > 50) { add_item_to_shop(12, 421, 1); }
	if (get_ran(1, 1, 100) > 50) { add_item_to_shop(12, 422, 1); }
	if (get_ran(1, 1, 100) > 50) { add_item_to_shop(12, 428, 1); }
	if (get_ran(1, 1, 100) > 50) { add_item_to_shop(12, 432, 1); }
	if (get_ran(1, 1, 100) > 50) { add_item_to_shop(12, 441, 1); }

	// shop 13 - magic weapons (Old Things - Colosse)
	if (get_ran(1, 1, 100) > 50) { add_item_to_shop(13, 344, 1); }
	if (get_ran(1, 1, 100) > 50) { add_item_to_shop(13, 345, 1); }
	if (get_ran(1, 1, 100) > 50) { add_item_to_shop(13, 348, 1); }
	if (get_ran(1, 1, 100) > 50) { add_item_to_shop(13, 351, 1); }
	if (get_ran(1, 1, 100) > 50) { add_item_to_shop(13, 381, 1); }
	if (get_ran(1, 1, 100) > 50) { add_item_to_shop(13, 442, 1); }
	if (get_ran(1, 1, 100) > 75) { add_item_to_shop(13, 452, 1); }
	if (get_ran(1, 1, 100) > 75) { add_item_to_shop(13, 453, 1); }

	// shop 14 - farm supplies (Tangramayne)
	add_item_to_shop(14, 161, 5);
	add_item_to_shop(14, 318, 5);
	add_item_to_shop(14, 377, 5);
	add_item_to_shop(14, 391, 5);
	add_item_to_shop(14, 392, 10);
	add_item_to_shop(14, 397, 500);
	add_item_to_shop(14, 398, 500);
	add_item_to_shop(14, 419, 10);
	add_item_to_shop(14, 437, 10);

	// 'balance' monsters (just lower levels if beginner party)
	// get max party level
	i = 0;
	lvl = 0;
	while (i < 4) {
		if (char_ok(i) == TRUE) {
			e = get_level(i);
			if (e > lvl) {
				lvl = e;
			}
		}
		i = i + 1;
	}
	if (lvl > 100) {
		lvl = 100;
	}
	set_flag(101, 0, lvl);

	// lower creature levels if party is 1 - 10
	if (lvl <= 10) {
		// mainly the wandering monsters types
		set_creature_type_level(13, 8);
		set_creature_type_level(19, 10);
		set_creature_type_level(107, 12);
		set_creature_type_level(108, 12);
		set_creature_type_level(123, 8);
		set_creature_type_level(124, 8);
		set_creature_type_level(125, 8);
		set_creature_type_level(176, 14);
		set_creature_type_level(163, 16);
		set_creature_type_level(164, 7);
		// other specials
		// zanta's level set in town he's in
		set_creature_type_level(236, 8);  // half level
		set_creature_type_level(250, 10);
		set_creature_type_level(251, 10);
		set_creature_type_level(252, 10);
	}
	else if (lvl <= 24) {
		// lower boss fight group levels
		set_creature_type_level(250, 15); // quarter off
		set_creature_type_level(251, 15);
		set_creature_type_level(252, 15);
	}
break;

// This state is called every tick wherever the party is in the scenario.
// You can use the set_state
beginstate START_STATE;
break;

// Place your own states below. Give each a number at least 10.
beginstate 10;
	set_flag(9, 2, TRUE);
	reset_dialog();
	add_dialog_str(0, "Due to the invasion of The Wilderness, the mine of Thessalonica is left devoid of activity.", 0);
	add_dialog_str(1, "The miners left in the region hope for the one day they can return and reopen the mine.", 0);
	add_dialog_str(2, "Until then, the mines are a dark and empty place.", 0);
	add_dialog_choice(0, "Ok");
	choice = run_dialog(TRUE);
break;

beginstate 11;
	if (get_flag(50, 1) > 0) {
		block_entry(TRUE);
		message_dialog("As you start to enter the mine, a group of miners stops you.",
			"'Sorry, with the mine in operation, only miners allowed in.' one of them says turning you back to the entrance.");
	}
break;

beginstate 12;
	reset_dialog();
	add_dialog_str(0, "There is a large metal plaque on the pedestal which reads:", 0);
	add_dialog_str(1, "Dedicated to those that helped destroy the followers of Zanta, who had taken up a position overlooking the town of Corinth", 10);
	add_dialog_str(2, "May the Zanta followers bodies rot forever in the sun.", 10);
	add_dialog_str(3, "It was kinda of ghoulish.", 0);
	add_dialog_choice(0, "Ok");
	choice = run_dialog(TRUE);
break;

beginstate 13;
	message_dialog("The books in these shelves are not very interesting.", "Math, science, physics - yuck!");
break;

beginstate 14;
	message_dialog("The shelves are full of books on rites and rituals for the Temple of Narn.",
		"Dry and boring, only The Bishop would want to read them.");
break;

beginstate 15;
	message_dialog("The shelves by the bed seem to be full of books of the fictional variety.",
		"Some of the titles make you think The Bishop has got some explaining to do...");
break;
